package com.xique.door.listener;

import com.xique.common.core.text.Convert;
import com.xique.door.constant.AccessCommandConstant;
import com.xique.door.device.command.AccessCommandHQService;
import com.xique.door.event.DelUserBatchCommandEvent;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author shd
 * @create 2021/7/3 10:17
 */
@Component
public class DelUserBatchCommandListener implements ApplicationListener<DelUserBatchCommandEvent> {


    @Autowired
    private AccessCommandHQService accessCommandService;

    /**
     *
     * @author shd
     * @date 2021/7/5 8:57
     * @param event 事件参数
     */
    @SneakyThrows
    @Override
    @Async
    public void onApplicationEvent(DelUserBatchCommandEvent event) {

        Map<String, List<String>> map = event.getDeleteData();

        for (String devSn : map.keySet()) {
            Map<String, List<String>> customIdMap = new HashMap<>(1);
            customIdMap.put("customId", map.get(devSn));
            Object o = accessCommandService.delBatchUserInfos(Arrays.asList(Convert.toStrArray(devSn)), customIdMap, AccessCommandConstant.VERSION);
            System.out.println("==========》批量用户删除：" + Arrays.asList(Convert.toStrArray(devSn)) + "===========>" + customIdMap + "=============>" + o.toString() + "==============>等待7秒");
            Thread.sleep(7000);
        }
    }
}
